//
//  ViewController.m
//  block的用法
//
//  Created by 谢伟 on 16/3/21.
//  Copyright © 2016年 wei.xie. All rights reserved.
//

#import "ViewController.h"
#import "XWTextFieldViewController.h"

@interface ViewController ()

@property (nonatomic,strong)UILabel *label;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 44)];
    self.label.backgroundColor = [UIColor blueColor];
    self.label.text = @"label";
    self.label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_label];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 200, 44)];
    [btn setTitle:@"push" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor blueColor];
    [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

- (void)btnClickAction:(UIButton *)btn {
    XWTextFieldViewController *vc = [[XWTextFieldViewController alloc] init];
    
    
    __weak typeof(self) weakSelf = self;
    [vc returnText:^(NSString *showText) {
        weakSelf.label.text = showText;
    }];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
